<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%
        String parentid = request.getParameter("parent.id");
        String id = request.getParameter("id");
        if (StringUtils.isEmpty(parentid)) {
            parentid = "";
        }
        if (StringUtils.isEmpty(id)) {
            id = "";
        }
    %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
        <%if (StringUtils.isEmpty(id)) {%>
        新增
        <%} else {%>
        修改
        <%}%>模块
    </title>
    <jsp:include page="../../../../head.jsp"/>
</head>

<script type="text/javascript">
    var pid = '<%=parentid%>';
    var id = '<%=id%>';
    var title = "新增";
    if (id) {
        title = "修改";
    }
    if (pid) {
        title += "子模块";
    } else {
        title += "模块";
    }
    var dropdownState = $.mrdForm.ajaxdp("dropdown-useState");
    var formSetting = {
        title: title,
        module: "save",
        numCount: 1,
        columns: [{
            name: "id",
            hidden: true
        }, {
            name: "name",
            label: "模块名称",
            validate: 'validate[required]'
        }, {
            name: "link",
            label: "链接地址",
            hidden: true
        }, {
            name: "state",
            label: "启用状态",
            type: "dropdown",
            data: dropdownState,
            value: "0",
            dropdownValue: "启用"
        }, {
            name: "order",
            label: "顺序",
            value: "99"
        }, {
            name: "parent.id",
            hidden: true,
            value: pid
        }],
        buttons: {
            custom: []
        },
        form: {
            url: "mod-modsave",
            'data': function () {
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "mod-modBeUpdate?id=" + id,
                               async: false,
                               success: function (data) {
//                                   if (data.module != null) {
//                                       var dropdownName = $.mrdForm
//                                               .getDropDwonLabelName("state");
//                                       data[dropdownName] = $.mrdForm
//                                               .dropdownShowValue(dropdownState,
//                                                                  data.state);
//                                   }
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            validate: {
                options: {
                    promptPosition: "bottomLeft"
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                var msg = $.parseJSON(responseText.msg);
                if (msg.state == "1") {
                    jw.close();
                    $('#west', window.parent.document)[0].contentWindow.refresh(pid);
                }
            }
        }
    };
    $(document).ready(function () {
        if (pid) {
            formSetting.columns[2].hidden = false;
        }
        $("#manage").mrdForm(formSetting);
    });
</script>
<body>
<div id="manage"></div>
</body>
</html>
